package org.medusa.db;

import org.medusa.core.EventCallback;
import org.medusa.db.handlersocket.InsertResult;
import org.medusa.db.handlersocket.ModifyResult;
import org.medusa.db.handlersocket.QueryOneResult;
import org.medusa.db.handlersocket.QueryResult;

public abstract class AsyncDBConnector {
	public abstract boolean IsConnected();

	public abstract Error Close();

	public abstract void Insert(String dbName, String tableName,
			String indexName, String[] columns, Object[] vals,
			EventCallback<InsertResult> callback);

	public void Insert(String dbName, String tableName, String indexName,
			String[] columns, Object[] vals) {
		this.Insert(dbName, tableName, indexName, columns, vals, null);
	}

	public abstract void Remove(String dbName, String tableName,
			String indexName, String oper, Object[] keys, int limit, int skip,
			EventCallback<ModifyResult> callback);

	public void Remove(String dbName, String tableName, String indexName,
			String oper, Object[] keys, EventCallback<ModifyResult> callback) {
		this.Remove(dbName, tableName, indexName, oper, keys,
				Integer.MAX_VALUE, 0, callback);
	}

	public void Remove(String dbName, String tableName, String indexName,
			String oper, Object[] keys, int limit, int skip) {
		this.Remove(dbName, tableName, indexName, oper, keys, limit, skip, null);
	}

	public void Remove(String dbName, String tableName, String indexName,
			String oper, Object[] keys) {
		this.Remove(dbName, tableName, indexName, oper, keys,
				Integer.MAX_VALUE, 0, null);
	}

	public abstract void Modify(String dbName, String tableName,
			String indexName, String oper, Object[] keys, String[] columns,
			Object[] newvals, int limit, int skip,
			EventCallback<ModifyResult> callback);

	public void Modify(String dbName, String tableName, String indexName,
			String oper, Object[] keys, String[] columns, Object[] newvals,
			EventCallback<ModifyResult> callback) {
		this.Modify(dbName, tableName, indexName, oper, keys, columns, newvals,
				Integer.MAX_VALUE, 0, callback);
	}

	public void Modify(String dbName, String tableName, String indexName,
			String oper, Object[] keys, String[] columns, Object[] newvals,
			int limit, int skip) {
		this.Modify(dbName, tableName, indexName, oper, keys, columns, newvals,
				limit, skip, null);
	}

	public void Modify(String dbName, String tableName, String indexName,
			String oper, Object[] keys, String[] columns, Object[] newvals) {
		this.Modify(dbName, tableName, indexName, oper, keys, columns, newvals,
				Integer.MAX_VALUE, 0, null);
	}

	public abstract void Query(String dbName, String tableName,
			String indexName, String oper, Object[] keys, String[] columns,
			int limit, int skip, EventCallback<QueryResult> callback);

	public void Query(String dbName, String tableName, String indexName,
			String oper, Object[] keys, String[] columns,
			EventCallback<QueryResult> callback) {

		this.Query(dbName, tableName, indexName, oper, keys, columns,
				Integer.MAX_VALUE, 0, callback);
	}

	public void Query(String dbName, String tableName, String indexName,
			String oper, Object[] keys, String[] columns, int limit, int skip) {
		this.Query(dbName, tableName, indexName, oper, keys, columns, limit,
				skip, null);
	}

	public void Query(String dbName, String tableName, String indexName,
			String oper, Object[] keys, String[] columns) {
		this.Query(dbName, tableName, indexName, oper, keys, columns,
				Integer.MAX_VALUE, 0, null);
	}

	public abstract void QueryOne(String dbName, String tableName,
			String indexName, String oper, Object[] keys, String[] columns,
			int skip, EventCallback<QueryOneResult> callback);

	public void QueryOne(String dbName, String tableName, String indexName,
			String oper, Object[] keys, String[] columns,
			EventCallback<QueryOneResult> callback) {

		this.QueryOne(dbName, tableName, indexName, oper, keys, columns, 0,
				callback);
	}

	public void QueryOne(String dbName, String tableName, String indexName,
			String oper, Object[] keys, String[] columns, int skip) {
		this.QueryOne(dbName, tableName, indexName, oper, keys, columns, skip,
				null);
	}

	public void QueryOne(String dbName, String tableName, String indexName,
			String oper, Object[] keys, String[] columns) {
		this.QueryOne(dbName, tableName, indexName, oper, keys, columns, 0,
				null);
	}
}
